<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>对象进行读写监听</title>
  </head>
  <body>
    <script>
      const obj = {
        name: 'layouwen',
      }
      Object.defineProperty(obj, 'name', {
        configurable: true,
        enumerable: true,
        get() {
          console.log('触发get')
          return 'layouwen'
        },
        set(newValue) {
          console.log('触发set')
          return newValue
        },
      })
      obj.name // 触发get
      obj.name = 'yuouwen' // 触发set
    </script>
  </body>
</html>
